import axios from 'axios'

const ajax = axios.create({
  baseURL: 'http://rap2api.taobao.org/app/mock/122976'
})

ajax.interceptors.request.use(config => {
  //console.log(config)
  // config.headers.authToken = 'ajaxpost'
  config.data = {
    ...config.data,
    authToken: 'ajaxpost'
  }
  return config
})

ajax.interceptors.response.use(resp => {
  //console.log(resp.data.data[0].list)
  console.log(resp)
  if (resp.data.code === 200) {
    return resp.data.data[0] || resp.data.data
  } else {
    return {
      errorMsg: resp.data.msg || '出错了！！'
    }
  }
})

// 前端分页接口
export const postUserList = () => {
  return ajax.post('api/v1/userList')
}
// 后端分页接口
export const postUserListPage = params => {
  // console.log(params)
  return ajax.post('/api/v1/userListPage', params)
}

// 删除接口
export const postDeleteUser = id => {
  return ajax.post(`/api/v1/user/delete/${id}`)
}
// // 热搜
// export const getData = () => {
//   return axios.get('h5ajax.php?action=hotword')
// }
